package com.ruoyi.bizsys.service.impl;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.stereotype.Service;
import com.ruoyi.bizsys.mapper.LoanOverflowMapper;
import com.ruoyi.bizsys.domain.LoanOverflow;
import com.ruoyi.bizsys.service.ILoanOverflowService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;


/**
 * 溢出金额Service业务层处理
 *
 * @author african-loan
 * @date 2021-10-28
 */
@Service
public class LoanOverflowServiceImpl extends ServiceImpl<LoanOverflowMapper, LoanOverflow> implements ILoanOverflowService {

    /**
     * 查询溢出金额
     *
     * @param id 溢出金额ID
     * @return 溢出金额
     */
    @Override
    public LoanOverflow selectLoanOverflowById(Long id) {
        return this.getById(id);
    }

    /**
     * 查询溢出金额列表
     *
     * @param loanOverflow 溢出金额
     * @return 溢出金额
     */
    @Override
    public List<LoanOverflow> selectLoanOverflowList(LoanOverflow loanOverflow) {
        return this.list(new QueryWrapper<>(loanOverflow).last("order by id desc"));
    }

    /**
     * 后台使用
     * @param loanOverflow 溢出金额
     * @return
     */
    @Override
    public List<LoanOverflow> getList(LoanOverflow loanOverflow) {
        if(loanOverflow.getParams().entrySet().size() > 0){
            return this.list(new QueryWrapper<>(loanOverflow).ge("create_time",loanOverflow.getParams().get("beginTime")).lt("create_time",loanOverflow.getParams().get("endTime")).last("order by id desc"));
        }
        return this.list(new QueryWrapper<>(loanOverflow).last("order by id desc"));
    }

    /**
     * 新增溢出金额
     *
     * @param loanOverflow 溢出金额
     * @return 结果
     */
    @Override
    public int insertLoanOverflow(LoanOverflow loanOverflow) {
        loanOverflow.setCreateTime(DateUtils.getNowDate());
        return baseMapper.insert(loanOverflow);
    }

    /**
     * 修改溢出金额
     *
     * @param loanOverflow 溢出金额
     * @return 结果
     */
    @Override
    public int updateLoanOverflow(LoanOverflow loanOverflow) {
        loanOverflow.setUpdateTime(DateUtils.getNowDate());
        return baseMapper.updateById(loanOverflow);
    }

    /**
     * 批量删除溢出金额
     *
     * @param ids 需要删除的溢出金额ID
     * @return 结果
     */
    @Override
    public int deleteLoanOverflowByIds(Long[] ids) {
        return baseMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除溢出金额信息
     *
     * @param id 溢出金额ID
     * @return 结果
     */
    @Override
    public int deleteLoanOverflowById(Long id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public LoanOverflow selectOneByHas(String custNo, String paymentReference) {
        return baseMapper.selectOneByHas(custNo,paymentReference);
    }

}
